package com.demo.xmtx.mapper;

import com.demo.xmtx.entity.Inventory;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface InventoryMapper {

  @Select("SELECT * FROM inventory WHERE product_id = #{productId}")
  Inventory selectInventoryByProductId(Long productId);

  @Update("UPDATE inventory SET stock = #{stock}, version = version + 1 " +
      "WHERE product_id = #{productId} AND version = #{version}")
  int updateInventoryWithVersion(Inventory inventory);
}
